package com.dbcs.servlets;

import java.io.IOException;
import java.util.Properties;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dbcs.utilidades.LeerPropiedades;

/**
 * Servlet implementation class ServletEntry
 */
@WebServlet("/ServletEntry")
public class ServletEntry extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	private static Properties propiedades = new LeerPropiedades().getProperties();
	private static final String URL_MAIN = propiedades.getProperty("URL_MAIN");
	private static final String URL_LOGGIN = propiedades.getProperty("URL_LOGGIN");
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletEntry() {
        super();
    }

    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		String url = null;
		
		// Compruebo si existe una variable de sesion con id=cliente
		
		if (request.getSession().getAttribute("cliente") != null){
			url = URL_MAIN;
		}else{
			url = URL_LOGGIN;
		}
		
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
		
		dispatcher.forward(request, response);
	}
    
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
